package com.seed.web.struts.sysmanager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.seed.commons.dbquery.PageViewForSQL;
import com.seed.commons.dbutil.DBBean;
import com.seed.service.sysmanager.IMenuItem;
import com.seed.web.core.BaseActionSupport;
import com.seed.web.form.sysmanager.MenuItemForm;

@Controller
@Scope("prototype")
public class MenuItemAction extends BaseActionSupport {

	private static final long serialVersionUID = 1L;

	private MenuItemForm menuitem;

	@Resource
	private IMenuItem menuitemService ;

	public MenuItemForm getMenuitem() {
		return menuitem;
	}

	public void setMenuitem(MenuItemForm menuitem) {
		this.menuitem = menuitem;
	}

	@Resource(name = "pageViewForSQL")
	private PageViewForSQL pv;

	public PageViewForSQL getPv() {
		return pv;
	}

	public void setPv(PageViewForSQL pv) {
		this.pv = pv;
	}

	public String updateMenuItem() throws Exception {
		
		return "" ;
	}
	
	public String saveMenuItem() throws Exception {
		boolean flag = this.menuitemService.saveMenuItem(menuitem);
		if (flag) {
			saveMessage("菜单列表添加成功！");
		} else {
			saveMessage("菜单列表添加 失败！");
		}
		return "msg";
	}

	public String findMenuItem() throws Exception {
		//加载二级菜单列表
		Map<String,Object[]> mapKeyChild = new HashMap<String,Object[]>() ;
		mapKeyChild.put("showMenuList", new Object[]{menuitem.getMenuModelFK()}) ;
		List<DBBean> dbchild = this.menuitemService.queryMenuItem(mapKeyChild) ;
		
		this.getBaseform().getRequest().setAttribute("MenuChild", dbchild);
		if ("findmeunmodel".equals(this.getBaseform().getType())) {
			return "findmeunmodel";
		} if ("privilegeitem".equals(this.getBaseform().getType())) {
			this.getBaseform().getRequest().setAttribute("roleId",this.getBaseform().getParam()) ;
			return "privilegeitem";
		} else {
			return "findmenumodelall";
		}
	}
}
